<template>
    <div class="test-paper-increase">
        <!-- 新增弹窗 -->
        <a-modal
         class="copyPaper-modal"
         :visible="visibleShow" 
         :title="'复制试卷'" 
         @ok="okChange" 
         @cancel="visibleShow = false"
         :width="620"
         :dialog-style="{ top: '40px' }"
         >
            <a-spin size="large" :spinning="spinning" :key="spinningKey">
                <div >
                    <a-form v-if="visibleShow" :form="form" layout="inline">
                        <a-form-item label="试卷名称">
                            <a-input
                            placeholder="请输入试卷名称"
                            v-decorator="[
                                'fsjmc', { initialValue:formState.fsjmc, rules: rules.fsjmc}
                            ]"/>
                        </a-form-item>
                        <a-form-item label="试卷类型">
                            <a-input
                            placeholder="请输入试卷类型"
                            v-model:value="formState.fsjlx"
                             />
                        </a-form-item>
                    </a-form>
                </div>
            </a-spin>
        </a-modal>
    </div>
</template>
<script>
import {typeInput, typeNumber, typeSelect, typeCheckbox, typeRadio} from '@/components/compSearchCriteria/ContractType'
import compSelector from '@/components/compSelector/compSelector'
import validator from '@/common/validator'
import {addServe, editServe, spcyPxSjjbxxcopySj} from './service/index'
import topicPage from './topicPage'
export default {
    components:{
        compSelector,
        topicPage
    },
    props:{
        fsjid:{
            type:String,
            default:'',
            require:false
        }
    },
    data(){
        return{
            spinningKey:null,
            spinning:false,
            form: this.$form.createForm(this, { name: 'coordinated' }),
            visibleShow:false,
            confirmLoading:false,
            typeSelect:typeSelect,
            formState:{},
            rules:{
                fsjmc: [{
                    required: true,
                    message: '请输入试卷名称',
                    trigger: 'blur',
                }],
                fsjlx: [{
                    required: true,
                    message: '请输入试卷类型',
                    trigger: 'blur',
                }]
            },
            formRequer:'',
            optionsArr:[],
            submittedSuccessfully:false,
            isAddATopic:false,//是否可以添加题目
            cuerrfsjid:''
        }
    },
    watch:{
        fsjid(newval,oldVal){
            //console.log('获取到试卷id了吗===========',newval)
            this.cuerrfsjid = newval
        }
    },
    mounted(){
        
    },
    methods:{
        cancelLoading(){
            let timer = setInterval((val)=>{
                this.spinning = false
                clearInterval(timer);
            },500)
            
        },
        getData(val){
            this.addEditParameter = val
            this.formState = val
        },
        //保存主表
        okChange(e) {
            // e.preventDefault();
            var formState = {}
            this.form.validateFields((err, values) => {
                if (!err) {
                    this.confirmLoading = true
                    formState = {
                        ...this.formState,
                        ...values
                    }
                    if(this.cuerrfsjid){
                        formState.id = this.cuerrfsjid
                    }
                    spcyPxSjjbxxcopySj(formState).then(res=>{
                        if(res.code == 200){
                            this.$message.success('保存成功')
                            this.confirmLoading = false
                            this.isAddATopic = true
                            this.visibleShow = false
                            this.$emit('AddHandleOk')
                        }else{
                            this.$message.warning(res.message)
                            this.confirmLoading = false
                        }
                    }).catch(err =>{
                        this.confirmLoading = false
                    })
                    
                }
            });
            
        },
        returnClick(){
            this.visibleShow = false
            this.$emit('handleOk',true,1)
            // this.handleSubmit()
        },
        refreshClick(){
            this.spinning = true
            this.spinningKey = Date.now()
            this.cancelLoading()
        },

    }

}

</script>
<style lang="less">
/* .ant-form-item-label{
    font-weight: 600;
} */
.copyPaper-modal{
    .ant-modal-title{
        font-weight: 600;
    }
    .ant-modal-header{
        background: #5ca3e5;
    }
    .ant-upload-list{
        display: none !important;
    }
    .ant-modal-footer .ant-btn-primary{
        border: 1px solid #5ca3e5 !important;
        background-color: #5ca3e5 !important;
        color: #fff !important;
    }
}
</style>